SpaceToDepth ================= 将输入张量的空间维按 ``block`` 重排到深度通道(Space → Depth)。 输入/输出均为 **NHWC** 格式:``[batch, height, width, channel]``。 要求输入高、宽 :math:`H`、:math:`W` 能被 :math:`B` 整除,其中 :math:`B` 为 ``block``。 设输入形状为 :math:`[N, H, W, C]`,则输出形状为: .. math:: \begin{aligned} N_{out} &= N \\ H_{out} &= H / B \\ W_{out} &= W / B \\ C_{out} &= C \cdot B^{2} \end{aligned} 元素总数不变。对输出坐标 :math:`(n, h, w)` 与块内偏移 :math:`(k_h, k_w)`、通道 :math:`c`: .. math:: \begin{aligned} y_{in} &= h \cdot B + k_h \\ x_{in} &= w \cdot B + k_w \\ c_{out} &= (k_h \cdot B + k_w) \cdot C + c \end{aligned} 即 :math:`O[n, h, w, c_{out}] = I[n, y_{in}, x_{in}, c]`。 本实现无 ``mode`` 参数,通道排列固定为上述形式(与 ``DepthToSpace`` 的 DCR 互逆)。 输入: - **input** - 输入数据地址 - **in_shape** - 输入形状,格式为 ``[batch, height, width, channel]`` - **block** - 分块因子 :math:`B` - **core_mask** - 核掩码(仅共享存储版本使用) 输出: - **output** - 输出数据地址 支持平台: ``FT78NE`` ``MT7004`` .. note:: - FT78NE 支持 int8, int16, int32, fp32, fp64, cplx64, cplx128 - MT7004 支持 int16, int32, fp16, fp32, cplx64 **共享存储版本:** .. c:function:: void i8_space_to_depth_s(int8_t *input, int8_t *output, int *in_shape, int block, int core_mask) .. c:function:: void i16_space_to_depth_s(int16_t *input, int16_t *output, int *in_shape, int block, int core_mask) .. c:function:: void i32_space_to_depth_s(int *input, int *output, int *in_shape, int block, int core_mask) .. c:function:: void hp_space_to_depth_s(float16 *input, float16 *output, int *in_shape, int block, int core_mask) .. c:function:: void fp_space_to_depth_s(float *input, float *output, int *in_shape, int block, int core_mask) .. c:function:: void dp_space_to_depth_s(double *input, double *output, int *in_shape, int block, int core_mask) .. c:function:: void c64_space_to_depth_s(float *input, float *output, int *in_shape, int block, int core_mask) .. c:function:: void c128_space_to_depth_s(double *input, double *output, int *in_shape, int block, int core_mask) **C调用示例:** .. code-block:: c :linenos: :emphasize-lines: 11 // MT7004 示例(共享存储多核,DDR 地址) void TestSpaceToDepthSMCFp32(int core_mask) { int core_id = get_core_id(); int logic_core_id = GetLogicCoreId(core_mask, core_id); int core_num = GetCoreNum(core_mask); float *input = (float *)0x81000000; float *output = (float *)0x82000000; int in_shape[4] = {1, 8, 8, 4}; int block = 2; sys_bar(0, core_num); fp_space_to_depth_s(input, output, in_shape, block, core_mask); } void main() { int core_mask = 0b1111; TestSpaceToDepthSMCFp32(core_mask); } **私有存储版本:** .. c:function:: void i8_space_to_depth_p(int8_t *input, int8_t *output, int *in_shape, int block) .. c:function:: void i16_space_to_depth_p(int16_t *input, int16_t *output, int *in_shape, int block) .. c:function:: void i32_space_to_depth_p(int *input, int *output, int *in_shape, int block) .. c:function:: void hp_space_to_depth_p(float16 *input, float16 *output, int *in_shape, int block) .. c:function:: void fp_space_to_depth_p(float *input, float *output, int *in_shape, int block) .. c:function:: void dp_space_to_depth_p(double *input, double *output, int *in_shape, int block) .. c:function:: void c64_space_to_depth_p(float *input, float *output, int *in_shape, int block) .. c:function:: void c128_space_to_depth_p(double *input, double *output, int *in_shape, int block) **C调用示例:** .. code-block:: c :linenos: :emphasize-lines: 7 // MT7004 示例(私有存储单核,AM 地址) void TestSpaceToDepthAMFp32(void) { float *input = (float *)0x10000000; float *output = (float *)0x10010000; int in_shape[4] = {1, 8, 8, 4}; int block = 2; fp_space_to_depth_p(input, output, in_shape, block); } void main() { TestSpaceToDepthAMFp32(); }